<?php
/**
 * Created by PhpStorm.
 * User: 董伟
 * Date: 2019/10/31
 * Time: 11:16
 */

namespace app\common\service;
use app\common\model\ShopType as ShopTypeModel;

class ShopType extends Base
{
    /**
     * 获取商品分类
     * @param string $where 查询条件
     * @param string $limit 分页条件
     * @param string $order 排序条件
     */
    public function categories($where = '', $limit = '', $order = 'list_order DESC,id ASC')
    {
        return ShopTypeModel::field(true)
            ->append(['image_uri', 'ad_uri'])
            ->where($where)
            ->order($order)->limit($limit)->select()->toArray();
    }

    /**
     * 获取所有终极栏目
     * @param  string $ids id
     */
    public function getLastCategories($ids)
    {
        $where = [
            ['id', 'in', $ids],
            ['is_last', 'eq', 1],
        ];
        return ShopTypeModel::where($where)->column('id');
    }

    /**
     * 获取分类列表--全部
     */
    public function all_cate($type=0){
        $list=ShopTypeModel::field("id,name,ad_id,image_id")->append(['image_uri', 'ad_uri'])->where('parent_id',0)->select()->toArray();
        foreach($list as $k=>$v){
            $list[$k]['sub']=ShopTypeModel::field("id,name,ad_id,image_id")->append(['image_uri', 'ad_uri'])->where('parent_id',$v['id'])->select();
        }
        return $list;
    }

    /**
     * 获取分类列表--子分类
     */
    public function sub_cate($parent_id=0){

        $list=ShopTypeModel::field("id,name,ad_id,image_id")->append(['image_uri', 'ad_uri'])->where('parent_id',$parent_id)->select()->toArray();

        return $list;
    }

}